package com.ljkj.common.db.dao;

import java.util.List;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.ljkj.access.Tuserrightrelation;
import com.ljkj.common.db.basedao.BaseDAO;


public class TUserRightRelationDAO extends BaseDAO {
	private static final Logger log = LoggerFactory.getLogger(TUserRightRelationDAO.class);
	// property constants
	
	public static final String POJONAME = "Tuserrightrelation";

	@Override
	protected void initDao() {
		// do nothingthis.setSessionFactory(sessionFactory);
	}

	public void save(Tuserrightrelation transientInstance) {
		log.debug("saving Tuserrightrelation instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void update(Tuserrightrelation tuserrightrelation) {
		log.debug("updating " + POJONAME + " instances");
		try {
			getHibernateTemplate().update(tuserrightrelation);
			log.debug("update successful");
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}
	}

	public void delete(Tuserrightrelation tuserrightrelation) {
		log.debug("deleting Tuser instance");
		try {
			getHibernateTemplate().delete(tuserrightrelation);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}


	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Tuserrightrelation instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Tuserrightrelation as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}


	public List findAll() {
		log.debug("finding all TUserRightRelation instances");
		try {
			String queryString = "from Tuserrightrelation";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Tuserrightrelation merge(Tuserrightrelation tuserrightrelation) {
		log.debug("merging Tuserrightrelation instance");
		try {
			Tuserrightrelation result = (Tuserrightrelation) getHibernateTemplate().merge(
					tuserrightrelation);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Tuserrightrelation instance) {
		log.debug("attaching dirty Tuserrightrelation instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Tuserrightrelation instance) {
		log.debug("attaching clean Tuser instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TUserRightRelationDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TUserRightRelationDAO) ctx.getBean("TUserRightRelationDAO");
	}
}